angular.module('starter.blackController', [])

//网友曝光主页面controller
.controller('NetworkCollectRecordController', function($scope, $state, networkCollectRecordService, $window, breakRecordsService, $timeout, breakRecordSelectService, CommonService, breakpromiselinkService, $ionicPopup, $ionicLoading) {
	try {
		var userId = JSON.parse($window.localStorage["user"] || '{}').userId;
		var token = JSON.parse($window.localStorage["user"] || '{}').token;
	} catch(error) {
		userId = 1;
		token = 2;
	}

	$scope.mes = "查无此人";

	//消息提示框
	$scope.showCheckSer = function(str) {
			var alertPopup = $ionicPopup.alert({
				title: "消息提示",
				template: str,
				okText: '确认',
				okType: 'button-balanced',
			});
		}
		//按钮颜色切换
	$scope.searchBtn = 0;
	//查询条件默认值
	$scope.condition = {
		condition: null,
	};
	$scope.changSearchBtn = function() {
		var condition = $scope.condition.condition;
		if(condition != null && condition != '') {
			//变蓝
			$scope.searchBtn = 1;
		} else {
			//不变蓝
			$scope.searchBtn = 0;
		}
	}

	$scope.isSelect = false;
	//数据处理（网友曝光、权威发布、失信联系人）
	$scope.breaksSort = function(num, condition, choice) {
		//如果点击的是"失信联系人"
		if(condition == 3) {
			$scope.isLinkClick = true;
		} else {
			$scope.isLinkClick = false;
		}
		$scope.isbreakRecords = false;
		$scope.isNetworkCollectRecords = false;
		$scope.num = num;

		//网友曝光list数据			
		if(num == 1) {
			//重置page为0
			pagen = 0;
			//重置加载更多
			$scope.noMore = false;
			//重置数据
			$scope.netBreaks = [];
			if(condition == 0 || condition == null) {
				$scope.noData1 = true;
			} else {
				$scope.noData1 = false;
				$scope.loadingData = "show";
			}
			$scope.loadingDataL = "hide";
			$scope.isNetworkCollectRecords = true;
			$scope.isbreakRecords = false;
			$scope.isBreakpromiselink = false;
			//重新调用查询数据方法
			networkCollectRecordService.getNetworkCollectRecordList(userId, token, pagen, num, condition, $scope.bandCardDataGo.province, $scope.bandCardDataGo.city, $scope.bandCardDataGo.district).then(function(response) {
				$scope.$broadcast('scroll.infiniteScrollComplete');
				$ionicLoading.hide();
				$scope.loadingData = "hide";
				if(response.data != null) {

					if(response.data.length > 0 && response.data.length < 9) {
						$scope.noMore = true;
						$scope.noData1 = false;
						$scope.mes = " 共查到" + response.data.length + "数据";
						//$scope.showCheckSer($scope.mes);	
					} else if($scope.bandCardDataGo.province != null) {
						$scope.noMore = true;
						$scope.noData1 = false;
						$scope.mes = " 共查到" + response.data.length + "数据";
						//$scope.showCheckSer($scope.mes);
					}
					if(response.data.length <= 0) {
						$scope.noMore = true;
						$scope.mes = "查无此人";
						if(pagen == 0) {
							$scope.noData1 = false;
						}
					} else {
						for(var i = 0; i < response.data.length; i++) {
							$scope.netBreaks.push(response.data[i]);
						}
						pagen = pagen + 1;
					}

				} else if(response.success == "nologin") {
					//$state.go('tab.zjr');
				}

			}, function(data) {
				//$state.go('tab.zjr');
			});
		} else {
			$scope.isNetworkCollectRecords = false;
		}

		//权威发布list数据
		if(num == 2) {
			//重置pageb为0
			$scope.pageb =0;
			//重置加载更多
			$scope.noMore = false;
			//重置数据
			$scope.authBreaks = [];

			$scope.noData2Go = 0;
			$scope.noData2 = true;
			if(condition == 0 || condition == null) {
				$scope.noData2 = true;
			} else {
				$scope.noData2 = false;
				$scope.loadingData = "show";

			}
		  //$ionicPopup.alert({title:'系统提示',template:$scope.pageb});
			$scope.loadingDataL = "hide";
			$scope.noData1 = false;
			$scope.isbreakRecords = true;
			$scope.isNetworkCollectRecords = false;
			$scope.isBreakpromiselink = false;
			//重新调用查询数据方法
			breakRecordsService.getBreakRecordsList(userId, token, $scope.pageb, num, condition, $scope.bandCardDataGo.province, $scope.bandCardDataGo.city, $scope.bandCardDataGo.district).then(function(response) {
				$scope.$broadcast('scroll.infiniteScrollComplete');
				$ionicLoading.hide();
				$scope.loadingData = "hide";

				//$ionicPopup.alert({title:'系统提示',template:response.data.length});
				
				if(response.data != null) {
					if(response.data.length > 0 && response.data.length < 9) {
						$scope.noMore = true;
						$scope.noData2 = false;
						$scope.mes = " 共查到" + response.data.length + "数据";
					} else if($scope.bandCardDataGo.province != null) {
						$scope.noMore = true;
						$scope.noData2 = false;
						$scope.mes = " 共查到" + response.data.length + "数据";
					}

					if(response.data.length <= 0) {
						$scope.noMore = true;
						$scope.mes = "查无此人";
						if($scope.pageb == 0) {
							$scope.noData2 = false;
						}
					} else {
						for(var i = 0; i < response.data.length; i++) {
							$scope.authBreaks.push(response.data[i]);
						}
						$scope.pageb = $scope.pageb + 1;
					}
				} else if(response.success == "nologin") {

				}

			});
		} else {
			$scope.isbreakRecords = false;
		}
		//失信联系人统计
		if(num == 3) {
			$scope.mes = "";
			$scope.noData3 = true;
			$scope.isBreakpromiselink = false;
			$scope.isNetworkCollectRecords = false;
			$scope.isbreakRecords = false;
			if($scope.isSelect) {
				$ionicLoading.hide();
			}
			if($scope.loadingDataLC) {
				$scope.loadingDataL = "hide";
				$scope.isBreakpromiselink = true;
				return 1;
			} else {
				$scope.loadingDataL = "show";
			}
			$scope.isBreakpromiselink = true;
		} else {
			$scope.isBreakpromiselink = false;
		}

	}
	$scope.loadingDataLC = false;
	if($scope.second == null) {
		//默认先显示出网络爆光
		$timeout(function() {
			$scope.breaksSort(1, 0);
			$scope.second = false;
			/*try {
				var allLinkCnt = $window.localStorage["allLinkCnt"];
				if(allLinkCnt != null) {
					$scope.allLinkCnt = $window.localStorage["allLinkCnt"];
					$scope.breakNamesAndNames = angular.fromJson($window.localStorage["breakNamesAndNames"]);
					$scope.linkMan = angular.fromJson($window.localStorage["linkMan"]);
					CommonService.getAllContacts().then(function(response) {
						var obj1 = [];
						var obj3 = [];
						//获取所有联系人
						var obj2 = response;
						for(i = 0; i < obj2.length - 1; i++) {
							if(obj2[i].phoneNumbers != null) {
								obj1.push(obj2[i].displayName + ':' + obj2[i].phoneNumbers[0].value);
								obj3.push(obj2[i].phoneNumbers[0].value);
								
							}
						}
						$scope.allLinkCntC = obj2.length;

						if($scope.allLinkCntC != $scope.allLinkCnt) {
							$scope.allLinkCnt = $scope.allLinkCntC;
							try {
								CommonService.getAllContacts().then(function(response) {
									$scope.loadingDataL = "show";
									var obj1 = [];
									var obj3 = [];
									var obj2 = response;
									for(i = 0; i < obj2.length - 1; i++) {
										if(obj2[i].phoneNumbers != null) {
											obj1.push(obj2[i].displayName + ':' + obj2[i].phoneNumbers[0].value);
											obj3.push(obj2[i].phoneNumbers[0].value);
										}
									}
									$scope.allLinkCnt = obj2.length;
									$scope.isLinkClick = false;
									$scope.isBreakpromiselink = false;
									if(obj2.length > 200) {
		;
										return;
									}
									$scope.allPone = angular.toJson(obj1, true);
									$scope.Pone = angular.toJson(obj3, true);
									if($scope.allPone.length > 0) {
										var allPone = "'" + $scope.allPone + "'";
										var Pone = "'" + $scope.Pone + "'";
										breakpromiselinkService.getBreakpromiselink(allPone, Pone).then(function(response) {
											if(response.success == "success") {
												$scope.loadingDataL = "hide";
												$scope.loadingDataLC = true;
												$scope.breaksSort(3);
												$scope.linkMan = response.data;
												$scope.isSelect = true;
												try {
													$scope.breakNamesAndNames = angular.fromJson($scope.linkMan.breakNamesAndNames);
												} catch(error) {
													$scope.showCheckSer("失信联系人格式错误");
													
												}
												$scope.isLinkClick = false;
											
												try {
													$window.localStorage["breakNamesAndNames"] = JSON.stringify($scope.breakNamesAndNames);
													$window.localStorage["allLinkCnt"] = $scope.allLinkCnt;
													$window.localStorage["linkMan"] = JSON.stringify($scope.linkMan);

												} catch(error) {

												}

											} else {
												$scope.linkMan.allLinkCnt = obj2.length;
												$scope.linkMan.breakCnt = 0;
												$scope.isLinkClick = false;
												$scope.showCheckSer("失信联系人获取失败");
											}
										})
									} else {
										$ionicLoading.show({
											template: '请授权！！！',
											showBackdrop: true,
											maxWidth: 200,
											showDelay: 0
										});
										$timeout(function() {
											$ionicLoading.hide();
										}, 1000)
										return 0;
									}
			
									if($scope.allLinkCnt == 0) {
										$scope.isLinkClick = false;
										$scope.isLinkClickShow = "hide";

										$timeout(function() {
											$ionicLoading.hide();
										}, 5000)
										return 0;
									}
								});
							} catch(error) {

							}

						} else {

							return 0;
						}

					});

				} else {
					try {
						CommonService.getAllContacts().then(function(response) {
							$scope.loadingDataL = "show";
							var obj1 = [];
							var obj3 = [];
							var obj2 = response;
							for(i = 0; i < obj2.length - 1; i++) {
								if(obj2[i].phoneNumbers != null) {
									obj1.push(obj2[i].displayName + ':' + obj2[i].phoneNumbers[0].value);
									obj3.push(obj2[i].phoneNumbers[0].value);
								}
							}
							$scope.allLinkCnt = obj2.length;
							$scope.isLinkClick = false;
							$scope.isBreakpromiselink = false;
							if(obj2.length > 200) {

								return;
							}
							$scope.allPone = angular.toJson(obj1, true);
							$scope.Pone = angular.toJson(obj3, true);
							if($scope.allPone.length > 0) {
								var allPone = "'" + $scope.allPone + "'";
								var Pone = "'" + $scope.Pone + "'";
								breakpromiselinkService.getBreakpromiselink(allPone, Pone).then(function(response) {
									if(response.success == "success") {
										$scope.loadingDataL = "hide";
										$scope.loadingDataLC = true;
										$scope.breaksSort(3);
										$scope.linkMan = response.data;
										$scope.isSelect = true;
										try {
											$scope.breakNamesAndNames = angular.fromJson($scope.linkMan.breakNamesAndNames);
										} catch(error) {
											$scope.showCheckSer("失信联系人格式错误");

										}
										$scope.isLinkClick = false;

										try {
											$window.localStorage["breakNamesAndNames"] = JSON.stringify($scope.breakNamesAndNames);
											$window.localStorage["allLinkCnt"] = $scope.allLinkCnt;
											$window.localStorage["linkMan"] = JSON.stringify($scope.linkMan);

										} catch(error) {

										}
									} else {
										$scope.linkMan.allLinkCnt = obj2.length;
										$scope.linkMan.breakCnt = 0;
										$scope.isLinkClick = false;
										$scope.showCheckSer("失信联系人获取失败");
									}
								})
							} else {
								$ionicLoading.show({
									template: '请授权！！！',
									showBackdrop: true,
									maxWidth: 200,
									showDelay: 0
								});
								$timeout(function() {
									$ionicLoading.hide();
								}, 1000)
								return 0;
							}
							if($scope.allLinkCnt == 0) {
								$scope.isLinkClick = false;
								$scope.isLinkClickShow = "hide";
								$ionicLoading.show({
									template: ' 你的没有联系人或者请授权！',
									showBackdrop: true,
									maxWidth: 200,
									showDelay: 0
								});

								$timeout(function() {
									$ionicLoading.hide();
								}, 5000)
								return 0;
							}
						});
					} catch(error) {

					}
			 }

			} catch(error) {
			 CommonService.getAllContacts().then(function(response) {
							$scope.loadingDataL = "show";
							var obj1 = [];
							var obj3 = [];
					
							var obj2 = response;
							for(i = 0; i < obj2.length - 1; i++) {
								
								if(obj2[i].phoneNumbers != null) {
								
									obj1.push(obj2[i].displayName + ':' + obj2[i].phoneNumbers[0].value);
								
									obj3.push(obj2[i].phoneNumbers[0].value);
								}
							}
			
							$scope.allLinkCnt = obj2.length;
							$scope.isLinkClick = false;
							$scope.isBreakpromiselink = false;
							if(obj2.length > 200) {

								return;
							}
							var obj4 = [];
							var obj5 = [];
							//start
							 for(i=0;i<=obj1.length-1;i++){
							 	obj4.push(obj1[i]);
							 	obj5.push(obj3[i]);
							   if( i=obj1.length-1){
					
							 	 
							 		break;
							 	}
                                if(i%9==0){
                                     
                                  obj4=[]; 
                                  obj5=[];  
                                }
									
							}
							 
	
							$scope.allPone = angular.toJson(obj1, true);

							$scope.Pone = angular.toJson(obj3, true);
							
							if($scope.allPone.length > 0) {
								var allPone = "'" + $scope.allPone + "'";
								var Pone = "'" + $scope.Pone + "'";
								breakpromiselinkService.getBreakpromiselink(allPone, Pone).then(function(response) {
									if(response.success == "success") {
										$scope.loadingDataL = "hide";
										$scope.loadingDataLC = true;
										$scope.breaksSort(3);
										$scope.linkMan = response.data;
										$scope.isSelect = true;
										try {
											$scope.breakNamesAndNames = angular.fromJson($scope.linkMan.breakNamesAndNames);
										} catch(error) {
											$scope.showCheckSer("失信联系人格式错误");

										}
										$scope.isLinkClick = false;
										try {
											$window.localStorage["breakNamesAndNames"] = JSON.stringify($scope.breakNamesAndNames);
											$window.localStorage["allLinkCnt"] = $scope.allLinkCnt;
											$window.localStorage["linkMan"] = JSON.stringify($scope.linkMan);

										} catch(error) {

                                        }
									} else {
										$scope.linkMan.allLinkCnt = obj2.length;
										$scope.linkMan.breakCnt = 0;
										$scope.isLinkClick = false;
										$scope.showCheckSer("失信联系人获取失败");
									}
								})
							} else {
								$ionicLoading.show({
									template: '请授权！！！',
									showBackdrop: true,
									maxWidth: 200,
									showDelay: 0
								});
								$timeout(function() {
									$ionicLoading.hide();
								}, 1000)
								return 0;
							}
							if($scope.allLinkCnt == 0) {
								$scope.isLinkClick = false;
								$scope.isLinkClickShow = "hide";
								$ionicLoading.show({
									template: ' 你的没有联系人或者请授权！',
									showBackdrop: true,
									maxWidth: 200,
									showDelay: 0
								});

								$timeout(function() {
									$ionicLoading.hide();
								}, 5000)
								return 0;
							}
				
						});
						
			}*/

		}, 0);
	}

	//去后台查询数据，加载过来loadNum=1（网络曝光）或者loadNum=2（权威发布）
	$scope.loadProduces = function(loadNum) {
			var num = 1;
			//加载网友曝光数据
			if(loadNum == 1) {
				if(pagen == '' || pagen == undefined || pagen == null) {

				} else {
					$scope.isNetworkCollectRecords = true;
					$scope.isbreakRecords = false;
					$scope.isBreakpromiselink = false;
					//重新调用查询数据方法
					networkCollectRecordService.getNetworkCollectRecordList(userId, token, pagen, num, $scope.bandCardDataGo.province, $scope.bandCardDataGo.city, $scope.bandCardDataGo.district).then(function(response) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if(response.data != null) {
							if(response.data.length > 0 && response.data.length < 9) {
								$scope.noData1 = false;
							}
							if(response.data.length <= 0) {
								$scope.noMore = true;
								if(pagen == 0) {
									$scope.noData = true;
								}
							} else {
								for(var i = 0; i < response.data.length; i++) {
									$scope.netBreaks.push(response.data[i]);
								}
								pagen = pagen + 1;
							}

						} else if(response.success == "nologin") {
							//$state.go('login');
						}
					});
				}

			}
			//加载权威发布页面
			if(loadNum == 2) {
				if($scope.pageb == 1) {
					$scope.pageb = 2;
				}
				if($scope.pageb == '' || $scope.pageb == undefined || $scope.pageb == null) {

				} else {
					$scope.noData2 = true;
					$scope.isbreakRecords = true;
					$scope.isNetworkCollectRecords = false;
					$scope.isBreakpromiselink = false;
					//重新调用查询数据方法
					breakRecordsService.getBreakRecordsList(userId, token, $scope.pageb, num, $scope.bandCardDataGo.province, $scope.bandCardDataGo.city, $scope.bandCardDataGo.district).then(function(response) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if(response.data != null) {
							if(response.data.length > 0 && response.data.length < 9) {
								$scope.noData1 = false;
							}
							if(response.data.length <= 0) {
								$scope.noMore = true;

								if($scope.pageb == 0) {
									$scope.noData2 = false;
								}
							} else {
								for(var i = 0; i < response.data.length; i++) {
									$scope.authBreaks.push(response.data[i]);
								}
								$scope.pageb = $scope.pageb + 1;
							}
						} else if(response.success == "nologin") {
							//$state.go('login');
						}

					});
				}

			}

		}
		// 默认点击网友查询爆发	
	$scope.search = function(condition) {
		$scope.isSearch = true;
		if($scope.condition.condition == null || $scope.condition.condition == '' || $scope.condition.condition == undefined) {
			$ionicLoading.show({
				template: ' 查询条件不能为空',
				showBackdrop: true,
				maxWidth: 200,
				showDelay: 0
			});

			$timeout(function() {
				$ionicLoading.hide();
			}, 1000)
		} else {
			$scope.breaksSort(2, $scope.condition.condition, 4);
		}

	}

	//定义数据模型
	$scope.bandCardData = {};
	$scope.bandCardDataGo = {};
	var vm = $scope.vm = {};
	vm.CityPickData = {
		areaData: ['全 国 '],
		buttonClicked: function() {
			var province = vm.CityPickData.areaData;
			$scope.bandCardData.province = province[0] + "-" + province[1];
			$scope.bandCardDataGo.province = province[0];
			$scope.bandCardDataGo.city = province[1];
			$scope.bandCardDataGo.district = province[2];
			$scope.breaksSort(2, $scope.condition.condition);
		},
		tag: '-'
	}

	$scope.goPublish = function() {

		if(userId == 1) {
			$state.go('login');
		} else {

			$state.go('tab.networkPublish');;
		}

	}

})

//网友曝光详情页面Controller
.controller('networkCollectRecordDetailController', function($scope, networkCollectRecordDetailService, $ionicLoading, $stateParams, $state, $window, $timeout, $ionicPopup) {
	var networkCollectRecordId = $stateParams.networkCollectRecordId;
	try {
		var userId = JSON.parse($window.localStorage["user"] || '{}').userId;
		var token = JSON.parse($window.localStorage["user"] || '{}').token;
	} catch(error) {
		userId = 1;
		token = 2;
	}
	//获取基本信息
	networkCollectRecordDetailService.getNetworkCollectRecordDetail(userId, networkCollectRecordId).then(function(response) {
			if(response.success == "success") {
				
				$scope.networkCollectRecordDetail = response.data;

			}
		})
		//获取违约图片信息
	networkCollectRecordDetailService.getnetworkCollectRecordPic(userId, networkCollectRecordId).then(function(response) {
		if(response.success == "success") {
			$scope.networkCollectRecordPics = response.data;

		}
	})
	$scope.searchBtnUn = "searchBtnUn";
	$scope.searchBtnUn1 = "searchBtnUn";
	//返回
	$scope.goBack = function(go) {
		if(go == 2) {
			$scope.searchBtnUn = "searchBtn";
			$timeout(function() {
				$scope.searchBtnUn = "searchBtnUn";
			}, 500)
		}
		if(go == 3) {
			$scope.searchBtnUn1 = "searchBtn";
			$timeout(function() {
				$scope.searchBtnUn1 = "searchBtnUn";
			}, 500)
		}

		$timeout(function() {
			if(go == 1) {
				$state.go('tab.black');
			}
			//申述提交
			if(go == 2) {
				$scope.searchBtnUn = "searchBtnUn";
				if(userId == 1) {
					$state.go('login');
				} else {
					$state.go('tab.allegemanaCommit', {
						breakRecordId: $stateParams.networkCollectRecordId
					});
				}
			}
			//网友曝光提交
			if(go == 3) {
				$scope.searchBtnUn1 = "searchBtnUn"
				if(userId == 1) {
					$state.go('login');
				} else {
					$state.go('tab.networkPublish', {
						breakRecordId: $stateParams.networkCollectRecordId
					});
				}

			}
		}, 600)
	}
	$scope.isShow = "hide";
	$ionicLoading.show({
		template: ' <ion-spinner icon="ios"></ion-spinner><br>',
		animation: 'fade-in',
		showBackdrop: true,
		maxWidth: 200,
		showDelay: 0
	});
	$timeout(function() {
		$ionicLoading.hide();
		$scope.isShow = "show;";
	}, 500)
})

// 权威发布详情页面Controller
.controller('breakRecordDetailController', function($scope, $stateParams, breakRecordDetailService, $state, $window, $ionicLoading, $timeout) {
	var breakRecordId = $stateParams.breakRecordId;
	try {
		var userId = JSON.parse($window.localStorage["user"] || '{}').userId;
		var token = JSON.parse($window.localStorage["user"] || '{}').token;
	} catch(error) {
		userId = 1;
		token = 2;
	}
	//计算违约时间
	$scope.selectDay = function(endtime, begintime) {
			//	    var begintime = new Date(Date.parse($("#begindate").val().replace(/-/g,   "/"))).getTime();  
			//	    var endtime = new Date(Date.parse($("#enddate").val().replace(/-/g,   "/"))).getTime();     
			var nTime = endtime - begintime;
			var day = Math.floor(nTime / 86400000);
			return day;
		}
		//基本信息
	breakRecordDetailService.getBreakRecordDetail(userId, breakRecordId).then(function(response) {
			if(response.success == "success") {
				$scope.breakRecordDetail = response.data;
				$scope.day = $scope.selectDay(new Date(), $scope.breakRecordDetail.startTime);
				
			}
		})
		//
	breakRecordDetailService.getBreakRecordDetailPic(userId, breakRecordId).then(function(response) {
		if(response.success == "success") {
			$scope.BreakRecordDetailPics = response.data;
             console.log(response);
		}
	})
	$scope.searchBtnUn = "searchBtnUn";
	$scope.searchBtnUn1 = "searchBtnUn";
	//返回
	$scope.goBack = function(go) {
		if(go == 2) {
			$scope.searchBtnUn = "searchBtn";
			$timeout(function() {
				$scope.searchBtnUn = "searchBtnUn";
			}, 500)
		}
		if(go == 3) {
			$scope.searchBtnUn1 = "searchBtn";
			$timeout(function() {
				$scope.searchBtnUn1 = "searchBtnUn";
			}, 500)
		}
		$timeout(function() {
			if(go == 1) {
				$state.go('tab.black');
			}
			if(go == 2) {
				$scope.searchBtnUn = "searchBtnUn";
				if(userId == 1) {
					$state.go('login');
				} else {

					$state.go('tab.allegemanaCommit', {
						breakRecordId: $stateParams.breakRecordId,
						type: 1
					});
				}

			}
			if(go == 3) {
				$scope.searchBtnUn = "searchBtnUn";
				if(userId == 1) {
					$state.go('login');
				} else {
					$state.go('tab.networkPublish', {
						breakRecordId: $stateParams.breakRecordId,
						type: 1
					});

				}

			}
		}, 550)

	}
	$scope.isShow = "hide";
	$ionicLoading.show({
		template: ' <ion-spinner icon="ios"></ion-spinner><br>',
		animation: 'fade-in',
		showBackdrop: true,
		maxWidth: 200,
		showDelay: 0
	});
	$timeout(function() {
		$ionicLoading.hide();
		$scope.isShow = "show;";
	}, 1000)

})

// 违约申述页面Controller
.controller('allegemanaCommitController', function($scope, $stateParams, $window, allegemanaCommitService, $state, $ionicPopup, $cordovaImagePicker, $cordovaCamera, CommonService, $window,$ionicLoading) {
	var breakRecordId = $stateParams.breakRecordId;
	var userId = JSON.parse($window.localStorage["user"] || '{}').userId;
	var token = JSON.parse($window.localStorage["user"] || '{}').token;
	if(userId == null || token == '' || token == null) {
		$state.go('login');
	}
	$scope.certificateNoZHAddressShow = 'show';
	$scope.certificateNoZAddressShow = 'show';
	$scope.certificateNoFAddressShow = 'show';
	//必填类对象
	var generalInfo = new Object();
	$scope.generalInfo = generalInfo;
	//上传图片 1本人手持身份证正面照片 2身份证正面图片  3手持身份证反面图片
	$scope.uploadPic = function(type) {
			try {
				if(type == 1) {
					var options = {
						maximumImagesCount: 1,
						quality: 70,
					};
					
					$cordovaImagePicker.getPictures(options).then(function(results) {
					if(results!=null&&results[0]!='O'&&results.length>0){
						    $ionicLoading.show({
	      			               template: '上传中，请稍后...'
	    		              });
						//上传
						CommonService.uploadPic(results[0]).then(function(response) {
							//上传成功
							if(response.success == 'success') {
								$scope.certificateNoZHAddress = response.message;
								//$scope.showCheckSer("上传 本人手持身份证正面照片 成功");
								$ionicLoading.hide();
								$ionicPopup.alert({title:'系统提示',template:"上传 本人手持身份证正面照片 成功"});
								$scope.certificateNoZHAddressShow = 'hide';
							}
						});
                     }else{
                     	    ionicLoading.hide();
                     	 	$ionicPopup.alert({title:'系统提示',template:"上传失败"});
		          	}
					
					});
				} else if(type == 2) {
					var options = {
						maximumImagesCount: 1,
						quality: 100,
						sourceType: 0
					};
					$cordovaImagePicker.getPictures(options).then(function(results) {
					if(results!=null&&results[0]!='O'&&results.length>0){
							$ionicLoading.show({
	      			               template: '上传中，请稍后...'
	    		              });
						//上传
						CommonService.uploadPic(results[0]).then(function(response) {
							//上传成功
							if(response.success == 'success') {
								$scope.certificateNoZAddress = response.message;
								//$scope.showCheckSer("上传 身份证正面图片 成功");
								$ionicLoading.hide();
								$ionicPopup.alert({title:'系统提示',template:"上传 身份证正面图片 成功"});
								$scope.certificateNoZAddressShow = 'hide';
							}
						});
					 }else{
					 	    $ionicLoading.hide();
		          			$ionicPopup.alert({title:'系统提示',template:"上传失败"});
		          	}	

					});

				} else if(type == 3) {
					var options = {
						maximumImagesCount: 1,
						quality: 100,
						sourceType: 0
					};
					$cordovaImagePicker.getPictures(options).then(function(results) {
						if(results!=null&&results[0]!='O'&&results.length>0){
							$ionicLoading.show({
	      			               template: '上传中，请稍后...'
	    		              });	
						//上传
						CommonService.uploadPic(results[0]).then(function(response) {
							//上传成功
							if(response.success == 'success') {
								$scope.certificateNoFAddress = response.message;
								//$scope.showCheckSer("上传  身份证反面图片 成功");
								$ionicLoading.hide();
								$ionicPopup.alert({title:'系统提示',template:"上传  身份证反面图片 成功"});
								$scope.certificateNoFAddressShow = 'hide';
							}
						});
                       }else{
                           	$ionicLoading.hide();
		          			$ionicPopup.alert({title:'系统提示',template:"上传失败"});
		          	}	

					});
				}
			} catch(error) {

			}

		}
		//提交违约申述信息
	$scope.user = {
		name: '',
		linkPhone: '',
		allegeRecord: ''
	};
	//提交违约申述信息	
	$scope.commitUserData = function() {
			var r = /^\+?[1-9][0-9]*$/;
			if($scope.user.name == '' || $scope.user.name == undefined || $scope.user.name == null) {
				$scope.showCheckSer('请输入用户名');
				return;
			}
			if($scope.user.linkPhone == '' || $scope.user.linkPhone == undefined || $scope.user.linkPhone == null) {
				$scope.showCheckSer('请输入号码');
				return;
			}
			if($scope.user.allegeRecord == '' || $scope.user.allegeRecord == undefined || $scope.user.allegeRecord == null) {
				$scope.showCheckSer('请输入申述原因');
				return;
			}
			if(!r.test($scope.user.linkPhone)) {
				$scope.showCheckSer('号码输入错误');
				return;
			}

			var certificateNoZHAddress = $scope.certificateNoZHAddress;
			var certificateNoZAddress = $scope.certificateNoZAddress;
			var certificateNoFAddress = $scope.certificateNoFAddress;

			if(certificateNoZHAddress == '' || certificateNoZHAddress == undefined || certificateNoZHAddress == null) {
				$scope.showCheckSer('请上传本人手持身份证正面照片');
				return;
			}
			if(certificateNoZAddress == '' || certificateNoZAddress == undefined || certificateNoZAddress == null) {
				$scope.showCheckSer('请上传本人身份证正面照片');
				return;
			}
			if(certificateNoFAddress == '' || certificateNoFAddress == undefined || certificateNoFAddress == null) {
				$scope.showCheckSer('请上传本人身份证反面照片');
				return;
			}
			allegemanaCommitService.getAllegemanaCommit(userId, $scope.user.name, $scope.user.linkPhone, $scope.user.allegeRecord, certificateNoZHAddress, certificateNoZAddress, certificateNoFAddress).then(function(response) {
				if(response.success == "success") {
					//$scope.showCheckSer("成功提交信息");
					$ionicPopup.alert({title:'温馨提示',template:"成功提交信息"}).then(function(res){
					$state.go("tab.black");	

		           });
				} else {
					$scope.showCheckSer("提交信息失败");
				}
			})
		}
		//消息提示框
	$scope.showCheckSer = function(str) {
		var alertPopup = $ionicPopup.alert({
			title: "消息提示",
			template: str,
			okText: '确认',
			okType: 'button-balanced',
		});
	}

	//返回主页面
	$scope.goBack = function(go) {
		if(go == 1) {
			if($stateParams.type == 1) {
				$state.go('tab.breakRecordDetail', {
					breakRecordId: $stateParams.breakRecordId
				});
			} else {
				$state.go('tab.networkCollectDetail', {
					networkCollectRecordId: $stateParams.breakRecordId
				});
			}
		}
	}

})

// 违约发布页面Controller
.controller('networkPublishController', function($scope, $stateParams, networkPublishService, $state, $ionicPopup, $cordovaImagePicker, $cordovaCamera, CommonService, $window,$ionicLoading) {
	var breakRecordId = $stateParams.breakRecordId;
	var userId = JSON.parse($window.localStorage["user"] || '{}').userId;
	var token = JSON.parse($window.localStorage["user"] || '{}').token;
	if(userId == null || token == '' || token == null) {
		$state.go('login');
	}

	//图片证据
	var lifePicAddressList = new Array();
	$scope.lifePicAddressList = lifePicAddressList;
	//上传图片可放多张 ，第一张为封面（都到15，第一张做头像）
	$scope.uploadPic = function(type) {
			try {
				//调用手机相册
				if(type == 4) {
					//$scope.showCheckSer('调用相册中...');
					var options = {
						maximumImagesCount: 10,
						quality: 100,
						sourceType: 0
					};
					$cordovaImagePicker.getPictures(options).then(function(results) {
						if(results!=null&&results[0]!='O'&&results.length>0){
							$ionicLoading.show({
	      			               template: '上传中，请稍后...'
	    		              });
	    		             var start =0;
						//这里可能选择了多张照片，需要进行循环上传
						for(var i = 0; i < results.length; i++) {
							//拍照成功后执行上传
							CommonService.uploadPic(results[i]).then(function(response) {
								//上传成功
								if(response.success == 'success') {
								     start++;
									//构建数据对象
									var object = new Object();
									object.lifePicAddress = response.message;

									//添加对象到集合
									$scope.lifePicAddressList.push(object);

									$ionicLoading.hide();
									//$ionicPopup.alert({title:'系统提示',template:"上传成功"});
								}
								if(start==results.length){
									$ionicPopup.alert({title:'系统提示',template:"上传成功"});
								}
								
							});
						}
						
					} else{
						$ionicLoading.hide();
						$ionicPopup.alert({title:'系统提示',template:"上传失败"});
					}
					});
				}

			} catch(error) {
			 // $scope.showCheckSer('调用相册失败');
			}

		}
		//提交的用户信息
	$scope.user = {
		name: '',
		phone: '',
		certificateNo: '',
		sexdata: '',
		title: '',
		defaultContent: '',
		qq: '',
		province: '',
		city: '',
		district: ''
	};
	$scope.commitUserData = function() {
			var r = /^\+?[1-9][0-9]*$/;
			if($scope.user.name == '' || $scope.user.name == undefined || $scope.user.name == null) {
				$scope.showCheckSer('请输入违约人名字');
				return;
			}
			if($scope.user.phone == '' || $scope.user.phone == undefined || $scope.user.phone == null) {
				$scope.showCheckSer('请输入违约人电话');
				return;
			}
			if($scope.user.certificateNo == '' || $scope.user.certificateNo == undefined || $scope.user.certificateNo == null) {
				$scope.showCheckSer('请输违约人身份证号');
				return;
			}
			if($scope.user.qq == '' || $scope.user.qq == undefined || $scope.user.qq == null) {
				$scope.showCheckSer('请输入违约人的QQ号');
				return;
			}
			if(!r.test($scope.user.qq)) {
				$scope.showCheckSer('QQ输入错误');
				return;
			}
			if(!r.test($scope.user.phone)) {
				$scope.showCheckSer('号码输入错误');
				return;
			}
			if($scope.user.title == '' || $scope.user.title == undefined || $scope.user.title == null) {
				$scope.showCheckSer('请输入标题');
				return;
			}
			if($scope.user.defaultContent == '' || $scope.user.defaultContent == undefined || $scope.user.defaultContent == null) {
				$scope.showCheckSer('请输入违约描述');
				return;
			}
			var picAddressList = angular.toJson($scope.lifePicAddressList, true);
			if(picAddressList == '[]' || picAddressList == '' || picAddressList == undefined || picAddressList == null) {
				$scope.showCheckSer('图片信息不能为空');
				return;
			}
	   //弹出提示风险和免责提示信息
	    var confirmPopup = $ionicPopup.confirm({
	       title: '违约信息发布注意事项及承诺：',
	       cancelText: '取消',
	       okText: '同意并提交',
	       template: '1.平台违约信息发布免费。<br />'+
	       '2.信息发布者独立承担违约信息真实性和完整性责任，因材料虚假导致的一切后果，由信息发布者自行承担。<br />'+
	       '3.本人承认已获违约人信息发布授权具有充分完整的违约人个人信息公示，使用权利。<br />'+
	       '以上内容及所附其他材料的真实性，如有虚假，由此引发的一切后果由本人承担。<br />'
	    });	
	    confirmPopup.then(function(res) {
	       if(res) {
			networkPublishService.getNetworkPublish(userId, $scope.user.name, $scope.user.phone, $scope.user.certificateNo, $scope.user.sexdata, $scope.user.title, $scope.user.defaultContent, $scope.user.qq, $scope.bandCardDataGo.province, $scope.bandCardDataGo.city, $scope.bandCardDataGo.district, picAddressList).then(function(response) {
				if(response.success == "success") {					
					$ionicPopup.alert({title:'温馨提示',template:"成功提交违约人信息"}).then(function(res){
					$state.go("tab.black");	

		           });
			  	} else {
					$scope.showCheckSer("提交信息违约人失败");
				}
			},function(e){
					$ionicLoading.hide();
					$ionicPopup.alert({title:'系统提示',template:'连接超时'});  	
			});	
	       }
	      });
/*			networkPublishService.getNetworkPublish(userId, $scope.user.name, $scope.user.phone, $scope.user.certificateNo, $scope.user.sexdata, $scope.user.title, $scope.user.defaultContent, $scope.user.qq, $scope.bandCardDataGo.province, $scope.bandCardDataGo.city, $scope.bandCardDataGo.district, picAddressList).then(function(response) {
				if(response.success == "success") {
					//$scope.showCheckSer("成功提交违约人信息");
					$ionicPopup.alert({title:'温馨提示',template:"成功提交违约人信息"}).then(function(res){
					$state.go("tab.black");	

		           });
			  	} else {
					$scope.showCheckSer("提交信息违约人失败");
				}
			})*/
		}
		//消息提示框
	$scope.showCheckSer = function(str) {
			var alertPopup = $ionicPopup.alert({
				title: "消息提示",
				template: str,
				okText: '确认',
				okType: 'button-balanced',
			});
		}
		//返回主页面
	$scope.goBack = function(go) {
		if(go == 1) {
			if($stateParams.type == 1) {
				$state.go('tab.breakRecordDetail', {
					breakRecordId: $stateParams.breakRecordId
				});
			} else {
				$state.go('tab.networkCollectDetail', {
					networkCollectRecordId: $stateParams.breakRecordId
				});
			}
		}
	}

	//定义数据模型
	$scope.bandCardData = {};
	$scope.bandCardDataGo = {};
	var vm = $scope.vm = {};
	vm.CityPickData = {
		areaData: ['点击选择地区'],
		buttonClicked: function() {
			var province = vm.CityPickData.areaData;
			$scope.bandCardData.province = province[0] + "-" + province[1];
			$scope.bandCardDataGo.province = province[0];
			$scope.bandCardDataGo.city = province[1];
			$scope.bandCardDataGo.district = province[2];
		},
		tag: '-'
	}

})